﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace 自定义配置提供者
{
    internal class Program
    {
        static void Main(string[] args)
        {
            ServiceCollection services = new ServiceCollection();
            services.AddScoped<TestWebConfig>();

            ConfigurationBuilder configBuilder = new ConfigurationBuilder();
            configBuilder.Add(new MyConfigSource() { Path = "web.config" });
            IConfigurationRoot configRoot = configBuilder.Build();

            services.AddOptions().Configure<WebConfig>(e => configRoot.Bind(e));
            using(var sp= services.BuildServiceProvider())
            {
                var c=sp.GetRequiredService<TestWebConfig>();
                c.Test();
            }
        }
    }
}
